#{extends 'main.html' /}
#{set title: 'Set Attendance : ' + meeting.name /}
#{set 'crumbs'}
<li><a href="/show/projects">Projects</a></li>
<li><a href="/show/project?id=${meeting.project.id}">${meeting.project.name}</a></li>
<li><a href="/projects/${meeting.project.id}/meetings"> Meetings and Events</a> </li>
<li><a href="/meetings/${meeting.id}">${meeting.name}</a></li>
#{/set}

<h3>${meeting.name} Attendance list</h3>

Here you can set the attendance of the users invited to ${meeting.name}
<br/>
Please note that When changing the status to not attending, you must enter a reason and click Set reason button to change the status.
<br/>
<br/>



#{list items:attendances, as:'attendance'}
	<li>
		<div style="width:200px !important">
		<a href="@{Show.user(attendance.user.id)}">${attendance.user.getDisplayName(meeting.project).raw()}</a>
		</div>
		&nbsp&nbsp<input type="radio" id="attendance_${attendance.id}_confirmed" name="attendance_${attendance.id}" onclick="set_confirmed(${attendance.id});" value="confirmed" #{if attendance.status=='confirmed'}checked#{/if}  /> attended
		&nbsp&nbsp<input type="radio" id="attendance_${attendance.id}_declined" name="attendance_${attendance.id}" onclick="show_reason(${attendance.id});"value="declined" #{if attendance.status=='declined'}checked#{/if} /> did not attend
		&nbsp&nbsp<span id="reason_${attendance.id}" style="display: ${attendance.status=='declined'?'blocked':'none'};">
			<input type=text id="text_reason_${attendance.id}" value="${attendance.reason}"/><span style="color:red">*</span>
			<input type=button id="button_$(attendance.id}" onclick="set_declined(${attendance.id});" value="Set reason">
		</span>
		<span id="success_declined_${attendance.id}" style="display:none; font-style: italic; font-size :90%; color : red;">
			&nbsp&nbsp Attendance changed to: did not attend
		</span>
		<span id="success_confirmed_${attendance.id}" style="display:none; font-style: italic; font-size :90%; color : green;">
			&nbsp&nbsp Attendance changed to: attended
		</span>
	</li>
	<br/>
#{/list}

<script type="text/javascript">
	
	function set_confirmed(id)
	{
		if(confirm("change status to attended??"))
		$.post('@{setConfirmed()}',{id: id}
		,function()
		{
			$('#success_declined_'+id).hide();
			$('#success_confirmed_'+id).show();
			$('#reason_'+id).hide();
		})
	}
	
	function set_declined(id)
	{
		var reno= document.getElementById("text_reason_"+id).value;
		if(reno.length>0)
		{
			var reason= $('text_reason_'+id);
			$.post('@{setDeclined()}',{id:id , reason:reno},
			function()
			{
				$('#success_declined_'+id).show();
				$('#success_confirmed_'+id).hide();
				$('#reason_'+id).hide();
				
			}
			)
		}
		else
		{
			alert("please enter a valid reason")
		}
	}
	
	function show_reason(id)
	{
		$('#reason_'+id).show();
	}

</script>
